# -*- coding:utf-8 -*-
import os
try:
    import maya.cmds as cmds
    import maya.mel as mel
except Exception as test_ERR:
    print('test')



def _run():
    ma_path = cmds.file(q=True, sn=True)
    if ma_path:
        dir_path = os.path.dirname(os.path.dirname(ma_path))
        fbx_dir_path = os.path.join(dir_path, 'fbx').replace('\\','/')
        if os.path.exists(fbx_dir_path):
            ma_fullname = os.path.split(ma_path)[1]
            ma_name = os.path.splitext(ma_fullname)[0]
            fbx_name = ma_name+'.fbx'
            fbx_path = os.path.join(fbx_dir_path,fbx_name).replace('\\','/')
            choose = cmds.confirmDialog(title='Export FBX', message=u'选择导出方式', icon='question',
                                        button=[u'导出所选择物体', u'导出全部场景', u'取消'], defaultButton=u'导出全部场景', cancelButton='取消')
            fbx_export = ''
            if choose == u'导出所选择物体':
                fbx_export = 'FBXExport -f "{}" -s'.format(fbx_path)
                
            elif choose == u'导出全部场景':
                fbx_export = 'FBXExport -f "{}" '.format(fbx_path)
                
            else:
                pass
            if fbx_export:
                mel.eval(fbx_export)
                cmds.confirmDialog(title=u'提示', message=u'输出FBX至\n{}'.format(fbx_path), button=['Yes'], defaultButton='Yes',
                                   dismissString='No')
        else:
            cmds.confirmDialog(title=u'提示', message=u'fbx目录不存在', button=['Yes'], defaultButton='Yes',
                               dismissString='No')
    else:
        cmds.confirmDialog(title=u'提示', message=u'ma文件不存在', button=['Yes'], defaultButton='Yes', dismissString='No')


def _doc():
    doc = {'name':u'导出FBX','doc':'导出全部场景或者选择物体'}
    return doc

